import {createRouter, createWebHashHistory} from 'vue-router'

import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

// @ts-ignore
const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: '/', //默认进入页面路径
            meta: {title: '登录'},
            component: () => import('../views/Login.vue')
        },
        {
            //重定向到login页面
            path: '/login',
            redirect: '/'
        },
        {
            path: '/index',
            meta: {title: '酒店信息管理平台'},
            component: () => import('../views/Index.vue'),
            children: [
                {
                    path: '',
                    meta: {title: '首页'},
                    component: () => import('../views/Home.vue')
                },
                {
                    path: '/mail',
                    meta: {title: '邮件'},
                    component: () => import('../views/Mail.vue')
                },
                {
                    path: '/Message',
                    meta: {title: '消息'},
                    component: () => import('../views/Message.vue')
                },
                {
                    path: '/Mine',
                    meta: {title: '个人中心'},
                    component: () => import('../views/user/Mine.vue')
                },
                {
                    path: '/Role',
                    meta: {title: '角色管理'},
                    component: () => import('../views/user/Role.vue')
                },
                {
                    path: '/SetPwd',
                    meta: {title: '修改密码'},
                    component: () => import('../views/user/SetPwd.vue')
                },
                {
                    path: '/User',
                    meta: {title: '员工管理'},
                    component: () => import('../views/user/User.vue')
                },
                {
                    path: '/Roomtype',
                    meta: {title: '房型管理'},
                    component: () => import('../views/room/RoomType.vue')
                },
                {
                    path: '/Room',
                    meta: {title: '房间管理'},
                    component: () => import('../views/room/Room.vue')
                },
                {
                    path: '/Assess',
                    meta: {title: '评价管理'},
                    component: () => import('../views/customer/Assess.vue')
                },
                {
                    path: '/Custom',
                    meta: {title: '客户管理'},
                    component: () => import('../views/customer/Custom.vue')
                },
                {
                    path: '/Order',
                    meta: {title: '订单管理'},
                    component: () => import('../views/customer/Order.vue')
                },
                {
                    path: '/Facility',
                    meta: {title: '设施管理'},
                    component: () => import('../views/Facility.vue')
                },

            ]
        },
        // 平台后台管理系统路由路径开始
        {
            path: '/Platform',
            meta: {title: '平台后端管理'},
            component: () => import('../views/haven/Platform.vue'),
            children: [
                {
                    path: 'Me',
                    meta: {title: '个人中心'},
                    component: () => import('../views/haven/Me.vue'),
                },
                {
                    path: '/rolePlat',
                    meta: {title: '角色管理'},
                    component: () => import('../views/haven/user/Role.vue')
                },
                {
                    path: '/userPlat',
                    meta: {title: '用户管理'},
                    component: () => import('../views/haven/user/User.vue')
                },
                {
                    path: '/Hotel',
                    meta: {title: '酒店管理'},
                    component: () => import('../views/haven/hotel/Hotel.vue')
                },
                {
                    path: '/Franchise',
                    meta: {title: '加盟审核'},
                    component: () => import('../views/haven/examine/Franchise.vue')
                },
                {
                    path: '/HotelExam',
                    meta: {title: '酒店审核'},
                    component: () => import('../views/haven/examine/HotelExam.vue')
                },
                {
                    path: '/RoomTypeExam',
                    meta: {title: '房型审核'},
                    component: () => import('../views/haven/examine/RoomTypeExam.vue')
                }
            ]
        }
        // 平台后台管理系统路由路径结束
    ]
})

// 使用路由守卫对网页标题进行切换，以及动画效果
router.beforeEach((to, from, next) => {
    NProgress.start();
    next()
})

router.afterEach((to, from) => {
    if (to.meta && to.meta.title) {
        document.title = to.meta.title
    }
    NProgress.done();
})

//将其暴露出去
export default router
